# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/4/10 9:08
Author : 田霄汉
Email : 522989570@qq.com
File : matplotlib_class07.py
Project : pandas_demo
Function : 单一柱状图
=======================================
"""

from config.setting import file_path
import pandas as pd
import matplotlib.pyplot as plt

excel07_path = file_path['excel_path'] + '/excel07.xlsx'

products = pd.read_excel(io=excel07_path,
                         skiprows=3,
                         usecols='C:F',
                         index_col='ID')
products.sort_values(by='PRICE', inplace=True, ascending=False)

# # 这里的DataFrame自带的plot功能
# products.plot.bar(x='BOOK_NUM', y='PRICE', color='red', title='International Books By BOOK_NUM')

# 调用plt里面的bar功能
plt.bar(x=products.BOOK_NUM, height=products.PRICE, color='red')
# 调整x轴旋转角度
plt.xticks(ticks=products.BOOK_NUM, rotation='90')
# 增加x轴、y轴的标签和title
plt.xlabel('BOOK_NUM')
plt.ylabel('PRICE')
plt.title('International Books by PRICE', fontsize=16)

# 让生成的柱状图更加紧凑
plt.tight_layout()
plt.show()
